package trong.gold.soft.com.model;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class createImg {
	  public static Image createImage(String filename)
	    {
	        Image image = null;
	        try
	        {
	            image = Image.createImage(filename);
	        }
	        catch (java.io.IOException ex)
	        {
	            // just let return value be null
	        }
	        return image;
	    }
	  public static Image createThumbnail(Image image,Graphics g,int re)
	  {
	     int sourceWidth = image.getWidth();
	     int sourceHeight = image.getHeight();
	     int thumbWidth = re;
	     int thumbHeight = -1;
	   
	     if (thumbHeight == -1)
	        thumbHeight = thumbWidth * sourceHeight / sourceWidth;
	   
	     Image thumb = Image.createImage(thumbWidth, thumbHeight);
	   
	     for (int y = 0; y < thumbHeight; y++)
	     {
	        for (int x = 0; x < thumbWidth; x++)
	        {
	          g.setClip(x, y, 1, 1);
	          int dx = x * sourceWidth / thumbWidth;
	          int dy = y * sourceHeight / thumbHeight;
	          g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
	        }
	     }
	     Image immutableThumb = Image.createImage(thumb);
	   
	     return immutableThumb;
	  }

}
